import {executeInCurrentTab} from "~background/utils";

const getLostHighlights = () => {
  function contentScriptGetLostHighlights() {
    if (window.top !== window.self) return; // JM：iframe调用检查
    if (!window.highlighterAPI){
      console.warn(`highlighterAPI is null, window.location: ${window.location}`);
      return [];
    } else {
      const lostHighlights = [];
      window.highlighterAPI.highlights.getAllLost().forEach((highlight, index) => lostHighlights.push({
        highlightText: highlight?.string,
        highlightComments: highlight?.comments,
        index
      }));
      return lostHighlights;
    }
  }

  return executeInCurrentTab({ func: contentScriptGetLostHighlights });
}

export default getLostHighlights;
